<!--
 * @Author: 谢小康 2170673706@qq.com
 * @Date: 2024-01-03 21:24:33
 * @LastEditors: 谢小康 2170673706@qq.com
 * @LastEditTime: 2024-02-04 10:17:11
 * @FilePath: \My-bolg\My_Blog\src\App.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup>

import { RouterView } from 'vue-router'
import Header from './components/header.vue';
import { ref, onMounted, onBeforeMount, watchEffect, nextTick, provide } from 'vue';
import { isMobile } from '@/utils/index.js'
import { MobleStore } from "@/stores/mobleOrPc.js"
import { SiteInfoStore } from "@/stores/baseSiteInfo.js"
import MYfooter from './components/footer.vue';
import BacktoTop from './components/BacktoTop.vue';
import { addsiteview } from "@/api/user.js"
import { useRoute } from 'vue-router'
import { useUser } from "@/stores/user.js"
import { getWelcomeSay } from "@/utils/index.js"
import Music from './components/music.vue';
let route = useRoute()
let moblestore = MobleStore()
let ismoble = ref(false)
let isshwo = ref(true)
function resize() {
  let width = document.body.clientWidth
  if (width <= 650) {
    ismoble.value = true
  } else {
    ismoble.value = false
  }
}
onBeforeMount(() => {
  resize()
  ismoble.value = isMobile()
  window.addEventListener('resize', resize)
})
watchEffect(() => {
  resize()
  moblestore.changeMoble(ismoble.value)
})
provide("reload", reload)
async function reload() {
  isshwo.value = false
  await nextTick();
  isshwo.value = true
}
function addviwe() {
  addsiteview().then(res => {
    if (res.data.status == 200) {
      console.log("上传访问量成功");
    }
  })
}
function welcome() {
  let user = ""
  let msg = ""
  if (JSON.parse(localStorage.getItem("userinfo"))) {
    user = JSON.parse(localStorage.getItem("userinfo")).username
  }
  if (JSON.parse(localStorage.getItem("userinfo")) && JSON.parse(localStorage.getItem("userinfo"))?.id == 2) {
    msg = '欢迎光临，猪大人'
  }
  msg = getWelcomeSay(user);
  ElNotification({
    title: '欢迎~~',
    message: msg,
    offset: 50,
  })
}
onMounted(() => {
  addviwe()
  if (window.name == "") {
    welcome();
    window.name = "isReload";
    localStorage.setItem("serchkeyword", JSON.stringify([]))
  }
})
</script>
<template>
  <Header v-if="route.meta.isshowheader"></Header>
  <Router-view v-if="isshwo"></Router-view>
  <MYfooter v-if="route.meta.isshowfooter"></MYfooter>
  <BacktoTop :svgRight=5></BacktoTop>
  <Music></Music>
</template>

<style lang="scss"></style>
